from google.appengine.ext import ndb

class StorageUnit(ndb.Model):
    name = ndb.StringProperty(required=True)
    description = ndb.TextProperty()
    location = ndb.TextProperty()
    slots = ndb.StringProperty(repeated=True)

    def query_containers(self):
        return Container.query(Container.storage_unit == self.key)

class Container(ndb.Model):
    name = ndb.StringProperty(required=True)
    description = ndb.TextProperty()
    storage_unit = ndb.KeyProperty(StorageUnit)
    slot = ndb.StringProperty()
    size_x = ndb.IntegerProperty()
    size_y = ndb.IntegerProperty()
    owner = ndb.UserProperty()

    def query_vials(self):
        return Vial.query(ancestor=self.key)

class VialGroup(ndb.Model):
    name = ndb.StringProperty()
    description = ndb.TextProperty()
    creation_date = ndb.DateProperty() # TODO: or DateTimeProperty
    color = ndb.StringProperty(indexed=False) # color in HTML format
    attachements = ndb.BlobKeyProperty(repeated=True)
    owner = ndb.UserProperty()

class Vial(ndb.Model):
    name = ndb.StringProperty()
    description = ndb.TextProperty()
    creation_date = ndb.DateProperty() # TODO: or DateTimeProperty
    x = ndb.IntegerProperty(required=True, indexed=False)
    y = ndb.IntegerProperty(required=True, indexed=False)
    owner = ndb.UserProperty()
    group = ndb.KeyProperty(VialGroup)
